package b.b.h;

import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import b.b.b;
import b.i.d.a;

/* compiled from: ThemeUtils */
public class a0 {
    public static final ThreadLocal<TypedValue> a = new ThreadLocal();
    public static final int[] b = new int[]{-16842910};
    public static final int[] c = new int[]{16842908};
    public static final int[] d = new int[]{16842919};
    public static final int[] e = new int[]{16842912};
    public static final int[] f = new int[0];
    public static final int[] g = new int[1];

    public static void a(View view, Context context) {
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(b.j);
        try {
            if (!obtainStyledAttributes.hasValue(115)) {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.append("View ");
                stringBuilder.append(view.getClass());
                stringBuilder.append(" is an AppCompat widget that can only be used with a Theme.AppCompat theme (or descendant).");
                Log.e("ThemeUtils", stringBuilder.toString());
            }
            obtainStyledAttributes.recycle();
        } catch (Throwable th) {
            obtainStyledAttributes.recycle();
        }
    }

    public static int b(Context context, int i) {
        ColorStateList d = d(context, i);
        if (d != null && d.isStateful()) {
            return d.getColorForState(b, d.getDefaultColor());
        }
        ThreadLocal threadLocal = a;
        TypedValue typedValue = (TypedValue) threadLocal.get();
        if (typedValue == null) {
            typedValue = new TypedValue();
            threadLocal.set(typedValue);
        }
        context.getTheme().resolveAttribute(16842803, typedValue, true);
        float f = typedValue.getFloat();
        int c = c(context, i);
        return a.c(c, Math.round(((float) Color.alpha(c)) * f));
    }

    public static int c(Context context, int i) {
        int[] iArr = g;
        iArr[0] = i;
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(null, iArr);
        try {
            i = obtainStyledAttributes.getColor(0, 0);
            return i;
        } finally {
            obtainStyledAttributes.recycle();
        }
    }

    public static ColorStateList d(Context context, int i) {
        int[] iArr = g;
        iArr[0] = i;
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(null, iArr);
        try {
            ColorStateList a;
            if (obtainStyledAttributes.hasValue(0)) {
                int resourceId = obtainStyledAttributes.getResourceId(0, 0);
                if (resourceId != 0) {
                    a = b.b.d.a.a.a(context, resourceId);
                    if (a != null) {
                        return a;
                    }
                }
            }
            a = obtainStyledAttributes.getColorStateList(0);
        } finally {
            obtainStyledAttributes.recycle();
        }
    }
}
